/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.element;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;

import de.mnit.basis.fehler.Fehler;

/**
 * @author Michael Nitsche
 *
 * TODO siehe mn.swt.dialog und mn.swt.komp.einfach.dialog
 */
public abstract class A_SWT_Dialog2<TA,TB extends Dialog> implements S_SWT_Komponente<TA,TB> {

	protected TA t;
	private TB swt;


	public TB erzeugeSWT(Widget vater) {
		Fehler.objekt.wenn_Null(vater);
		Fehler.objekt.wenn_KlasseFalsch(vater, Shell.class);
		if(!this.erzeugt())
			this.iErzeugeSWT((Shell)vater);
		return this.swt;
	}

	public TB swt() {
		return this.swt;
	}


	protected abstract int  style();
	protected abstract TB   roh(Shell vater, int style);
	protected abstract void init();

	protected boolean erzeugt() {
		return this.swt!=null;
	}

	@SuppressWarnings("unchecked")
	private final TB iErzeugeSWT(Shell vater) {
		this.t=(TA)this;
		this.swt=this.roh(vater,this.style());
		Fehler.objekt.wenn_Null(this.swt);
		this.init();
		return this.swt;
	}

}
